package com.ruoyi.system.Control;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;

public class DiagonalBordersExample {
    public static void main(String[] args) throws Exception {
        Workbook workbook = new XSSFWorkbook(); // 创建新的Excel工作簿
        Sheet sheet = workbook.createSheet("Sheet1"); // 创建一个工作表

        // 创建一个单元格样式，设置对角线框
        CellStyle style = workbook.createCellStyle();
        style.setBorderTop(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderLeft(BorderStyle.THIN);

        // 设置对角线框的宽度和样式
     //  style.setDiagonalBorderColor(IndexedColors.BLACK.getIndex());
      //  style.setDiagonalBorder(BorderDiagonal.BACKWARD, BorderStyle.THIN);

        // 在工作表中应用样式
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellStyle(style);

        // 写入文件
        FileOutputStream fileOut = new FileOutputStream("D:\\diagonal_borders.xlsx");
        workbook.write(fileOut);
        fileOut.close();

        workbook.close();
    }
}
